<div id="wrapper">

    <!-- Navigation -->
    <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="" ng-clikc="">Obieg dokumentów - EDI</a>
        </div>
        <!-- /.navbar-header -->
        <ul class="nav navbar-top-links navbar-right">

            <li class="dropdown">
                <a class="dropdown-toggle" data-toggle="dropdown" href="dropdown">
                    <i class="fa fa-user fa-fw"></i>  <span ng-if="currentUser" >{{ currentUser.email}}</span> <i class="fa fa-caret-down"></i>
                </a>
                <ul class="dropdown-menu dropdown-user">
                    <li><a href="#" ng-click="logout()"><i class="fa fa-sign-out fa-fw"></i> Wyloguj</a>
                    </li>
                </ul>
                <!-- /.dropdown-user -->
            </li>
            <!-- /.dropdown -->
        </ul>
        <!-- /.navbar-top-links -->

        <div class="navbar-default sidebar" role="navigation">
            <div class="sidebar-nav navbar-collapse">
                <ul class="nav" id="side-menu">
                    <li ng-repeat="dep in deps">
                        <a ng-click="" ng-if="dep.depId == currentUser.depId"class="active"><i class="fa fa-table fa-fw"></i> {{dep.depName}}</a>
                    </li>
                </ul>
            </div>
            <!-- /.sidebar-collapse -->
        </div>
        <!-- /.navbar-static-side -->
    </nav>

    <div id="page-wrapper" ng-controller="MainCtrl as showCase">
        <div class="row">
            <div class="col-lg-12 mainRow">				
                <button class="btn btn-primary pull-right" style="margin:10px 0px;" ng-click="goToUpload(0)"><i class="fa fa-plus"></i> Dodaj plik</button>
                <button class="btn btn-primary pull-right" style="margin:10px;" ng-click="refreshTable()"><i class="fa fa-refresh"></i> Odśwież tabele</button>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        Dostępne pliki
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="table-responsive" >
                            <table datatable="ng" class="table table-striped table-hover" id="dataTables-example">
                                <thead>
                                    <tr>
                                        <th>Nazwa pliku</th>
                                        <th style="width: 125px;">Status</th>
                                        <th style="width: 160px;">Ostatnia modyfikacja</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr ng-repeat="file in showCase.files">
                                        <td style="vertical-align: middle;">
                                            <i ng-if="file.extension == 'png'" class="fa fa-file-pdf-o fa-2x"></i>
                                            <i ng-if="file.extension == 'xls' || file.extension == 'xlsx' || file.extension == 'ods'" class="fa fa-file-excel-o fa-2x"></i>
                                            <i ng-if="file.extension == 'doc' || file.extension == 'odt' || file.extension == 'docx'" class="fa fa-file-word-o fa-2x"></i>
                                            <i ng-if="file.extension == 'txt'" class="fa fa-file-text-o fa-2x"></i>
                                            <i ng-if="file.extension == 'jpg' || file.extension == 'png' || file.extension == 'gif'" class="fa fa-file-image-o fa-2x"></i>
                                            <i ng-if="file.extension == 'html' || file.extension == 'xml'|| file.extension == 'css'|| file.extension == 'js'" class="fa fa-file-code-o fa-2x"></i>
                                            <i ng-if="
                                                file.extension != 'png' &&
                                                file.extension != 'img' &&
                                                file.extension != 'gif' &&
                                                file.extension != 'pdf' &&
                                                file.extension != 'xls' &&
                                                file.extension != 'xlsx' &&
                                                file.extension != 'ods' &&
                                                file.extension != 'odt' &&
                                                file.extension != 'doc' &&
                                                file.extension != 'docx' &&
                                                file.extension != 'txt' &&
                                                file.extension != 'html' &&
                                                file.extension != 'xml' &&
                                                file.extension != 'css' &&
                                                file.extension != 'js'
                                                " class="fa fa-file-o fa-2x"></i>
                                            <span style="margin-left:10px;">{{file.name}}</span>
                                            <div class="btn-group pull-right">
                                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                    <i class="glyphicon  glyphicon glyphicon-th-list"></i>
                                                </button>
                                                <ul class="dropdown-menu" role="menu">
                                                    <li>
                                                        <a href="document/downloadFile/{{file.id}}" target="_blank" title="Pobierz">
                                                            <i class="glyphicon glyphicon-download"></i> Pobierz
                                                        </a>
                                                    </li>
                                                    <li>
                                                        <a ng-if="file.lockUserId == currentUser.userId && file.isFinal == 0" ng-click="goToUpload(file.id)" title="Wczytaj">
                                                            <i class="glyphicon glyphicon-upload"></i> Wczytaj
                                                        </a>
                                                    </li>
                                                    <li>
                                                        <a ng-if="file.lockUserId == null && file.isFinal == 0" ng-click="blockFile(file.id)" title="Zablokuj">
                                                            <i class="glyphicon glyphicon-ban-circle"></i> Zablokuj
                                                        </a>
                                                    </li>
                                                    <li>
                                                        <a ng-if="file.lockUserId == currentUser.userId && file.isFinal == 0" ng-click="unblockFile(file.id)"  title="Odblokuj">
                                                            <i class="glyphicon glyphicon-ok-circle"></i> Odblokuj
                                                        </a>
                                                    </li>
                                                    <li>
                                                        <a ng-if="file.lockUserId == currentUser.userId || file.isFinal == 1 || file.lockUserId == null" ng-click="showModal(file.id)" data-toggle="modal"  data-target=".file_move"><i class="glyphicon glyphicon-send"></i> Przekaż</a>
                                                    </li>
                                                    <li>
                                                        <a ng-if="(file.lockUserId == currentUser.userId || file.lockUserId == null) && file.isFinal == 0" ng-click="closeFile(file.id)" title="Zamknij">
                                                            <i class="glyphicon glyphicon-off"></i> Zamknij
                                                        </a>
                                                    </li>
                                                    <li class="divider"></li>
                                                    <li>
                                                        <a ng-click="showFileHistory(file.id)" data-toggle="modal" data-target=".file_history"><i class=" glyphicon glyphicon-book"></i> Historia</a>
                                                    </li>
                                                    <li>
                                                        <a ng-if="(file.lockUserId == currentUser.userId || file.lockUserId == null) && file.isFinal == 0"  ng-click="removeFile(file.id)"><i class=" glyphicon glyphicon-trash"></i> Usuń</a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                        <td style="vertical-align: middle;">
                                            <span ng-if="file.lockUserId == null && file.isFinal == 0">Wolny</span>
                                            <span ng-if="file.lockUserId != null && file.isFinal == 0">Zablokowany</span>
                                            <span ng-if="file.isFinal == 1">Finalny</span>
                                        </td>
                                        <td style="vertical-align: middle;">
                                            <span ng-if="file.lastModifiedDate == null && file.createdDate == null">0000-00-00 00:00:00</span>
                                            <span ng-if="file.lastModifiedDate == null && file.createdDate != null">{{file.createdDate.year}}-{{file.createdDate.monthOfYear}}-{{file.createdDate.dayOfYear}} {{file.createdDate.hourOfDay}}:{{file.createdDate.minuteOfHour}}</span>
                                            <span ng-if="file.lastModifiedDate != null">{{file.lastModifiedDate.year}}-{{file.lastModifiedDate.monthOfYear}}-{{file.lastModifiedDate.dayOfYear}} {{file.lastModifiedDate.hourOfDay}}:{{file.lastModifiedDate.minuteOfHour}}</span>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <div class="modal fade file_move" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
                            <div class="modal-dialog modal-lg">
                                <div class="modal-content">
                                    <form role="form" ng-submit="moveFile(passFileData)">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                                            <h4 class="modal-title" id="myModalLabel">Przekaż plik</h4>
                                        </div>
                                        <div class="modal-body">
                                            <div class="form-group">
                                                <label for="exampleInputEmail1">Dział</label>
                                                <select class="form-control" ng-model="passFileData.departmentID"
                                                        ng-options="dep.depId as dep.depName for dep in deps">
                                                    <option value="">wybierz</option>
                                                </select>
                                            </div>
                                            <div class="form-group">
                                                <label for="exampleInputPassword1">Osoba</label>
                                                <select class="form-control" ng-model="passFileData.userID">
                                                    <option value="">wszyscy</option>
                                                    <option ng-repeat="worker in workers" ng-value="worker.employeeID">{{ worker.employeeName}} {{worker.employeeSurname }}</option>
                                                </select>
                                            </div>
                                            <div class="form-group">
                                                <label for="exampleInputEmail1">Notatka</label>
                                                <textarea class="form-control" style="height: 200px;" ng-model="passFileData.comment"></textarea>
                                                <input class="file_input" style="display:none;" type="text" value="" ng-model="passFileData.fileID">
                                            </div>
                                        </div>
                                        <div class="modal-footer moveFileMainRow">
                                            <input type="submit" class="btn btn-primary" value="Przekaż"/>
                                            <button type="button" class="btn btn-default" data-dismiss="modal">Zamknij</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <div class="modal fade file_history" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                                        <h4 class="modal-title" id="myModalLabel">Historia pliku</h4>
                                    </div>
                                    <div class="modal-body">

                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">Zamknij</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
    </div>
    <!-- /#page-wrapper -->
    <script>
                                                $(document).ready(function() {


                                        });    </script>
</div>
